/*
 * Droplet.cpp
 *
 * Created: 5/11/2012 4:13:57 PM
 *  Author: common
 */ 
<<<<<<< HEAD
#define F_CPU 32000000UL
=======
>>>>>>> origin/master

#include <avr/io.h>
#include <math.h>
#include <util/delay.h>

#include "motor.h"
#include "RGB_LED.h"
<<<<<<< HEAD
#include "pc_com.h"
#include "RGB_sensor.h"
#include "power.h"


void Config32MHzClock(void)
{
	// initialize clock source to be 32MHz internal oscillator (no PLL)
	CCP = CCP_IOREG_gc;							//Security Signature to modify clock
	OSC.CTRL = OSC_RC32MEN_bm;					// enable internal 32MHz oscillator
	while(!(OSC.STATUS & OSC_RC32MRDY_bm));		// wait for oscillator ready
	CCP = CCP_IOREG_gc;							//Security Signature to modify clock
	CLK.CTRL = 0x01;							//select sysclock 32MHz osc
}

int main(void)
{
	Config32MHzClock();
	
	motor_init();
	RGB_LED_init();
	pc_com_init();
	
	char i = 0;
	
	printf("Press any key to pause/unpause. \r\n");
	
	set_blue_led(50);
	_delay_ms(500);
	led_off();
	
	while (1)
	{
		if (PC_USART.STATUS & USART_RXCIF_bm)
		{
			i = PC_USART.DATA;
			printf("\r\nPaused (%c) \r\n", i);
			while (!(PC_USART.STATUS & USART_RXCIF_bm));	
			i = PC_USART.DATA;
		}

		printf("%c  ", ++i % 26 + 'A');
		
		for (uint8_t j = 0; j < 5; j++)
		{
			set_red_led(40);
			_delay_ms(100);
			led_off();
			_delay_ms(900);
		}
		set_green_led(40);
		_delay_ms(500);
		led_off();
		
		spin(COUNTERCLOCKWISE, 100);
		_delay_ms(1000);
		stop();
		
=======

int main(void)
{
	motor_init();
	RGB_LED_init();
	
	uint8_t dir = 0, speed = 0, i = 0;
	
	while (1)
	{
		for (dir = 0; dir < 6; dir++)
		{
			// Blink red 10 times on reset
			for (i = 0; i < 10; i++)
			{
				set_red(255);
				_delay_ms(500);
				set_red(0);
				_delay_ms(500);
			}
		
			// Blink green dir times to indicate direction
			for (i = 0; i < dir; i++)
			{
				set_green(255);
				_delay_ms(500);
				set_green(0);
				_delay_ms(500);
			}
				
			// Blink blue speed / 10 times to indicate speed
			for (i = 0; i < speed / 10; i++)
			{
				set_blue(255);
				_delay_ms(500);
				set_blue(0);
				_delay_ms(500);
			}		
		
			// Move in direction
			move(dir, speed);
			_delay_ms(5000);
			stop();
		}		
		
		speed += 10;
		if (speed > 250) speed = 0;
>>>>>>> origin/master
	}	
}